package Test11_04;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnectionDemo04 {
	public static final String DBDRIVER = "com.mysql.jdbc.Driver";
	public static final String DBURL = "jdbc:mysql://localhost:3306/publicdemoprac";
	public static final String DBUSER = "root";
//	public static final String DBPASS = "root";
	public static final String DBPASS = "123456";
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Connection conn = null;
		Statement stat = null;
		ResultSet rs = null;
		String query = "select id,name,password,age from user";
		try{
			Class.forName(DBDRIVER);
			conn=DriverManager.getConnection(DBURL, DBUSER, DBPASS);
			stat = conn.createStatement();
			rs = stat.executeQuery(query);
			while(rs.next()){
				int id = rs.getInt("id");
				String name = rs.getString("name");
				String password = rs.getString("password");
				int age = rs.getInt("age");
				System.out.println(id+"--->"+name+"--->"+password+"--->"+age);
			}
			rs.close();
			stat.close();
			conn.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
